<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<link href="css/common.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="js/jquery-1.4.1.js"></script>
	
	<script type="text/javascript">
		$(function(){
			$(":button").click(function(){
				
				//验证用户名
				if($(":text").val() == "") {
					alert("用户名不能为空。");
					$(":text").select();
					return false;
				}
				
				//验证密码
				if($(":password").val() == "") {
					alert("密码不能为空");
					$(":password").select();
					return false;
				}
				
				//发ajax请求
				var url ="${pageContext.request.contextPath}/login";
				var data={
						username:$(":text").val(),
						password:$(":password").val()
				};
				var callback= function(data){
					//把字符串转化为json对象
					var r = eval("("+data+")");
					if(r.status == 0){
						alert(r.errorInfo);
					}else{
						window.location.href = r.url;
					}
				};
				
				$.post(url,data,callback);
			});
		});
	</script>
</head>
<body>
	<table>
		<tr>
			<th colspan="2" align="left"><h2>用户登录</h2></th>
		</tr>
		<tr>
			<td>用户名</td>
			<td><input type="text" name="username" value="scott"></td>
		</tr>
		<tr>
			<td>密码</td>
			<td><input type="password" name="password" value="123456"></td>
		</tr>
		<tr>
		<tr>
			<td colspan="2" align="center"><input type="button" value="登录">
				<a href="${pageContext.request.contextPath}/pre">注册</a>
			</td>
		</tr>
	</table>
</body>
</html>